{extends file="../global.html"}
{block name=body}

 
{if $error}
  <p style="color:red">{$error}</p>
{else}

{/if}
<h3>品牌修改</h3>
<form class="layui-form"  method="post" enctype="multipart/form-data" action="{url('run/type/update')}">
  <div class="layui-form-item">
    <label class="layui-form-label">品牌名称</label>
    <div class="layui-input-block">
      <input type="text" name="type_name" required id="typename" value="{$res.type_name}" lay-verify="required"  autocomplete="off" class="layui-input"><span id="span"></span>
    </div>
  </div>

  <div class="layui-form-item">
   <label class="layui-form-label">品牌图片</label>

  <input type="file" name="file" id="imgPicker" >
  <img id="preview" src="{$absroot}{$res.type_pic}" width="100"/>
  </div>
  <input type="hidden" name="type_id" value="{$res.type_id}">
  <input type="hidden" name="type_pic" value="{$res.type_pic}">
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" id="btn" lay-submit lay-filter="formDemo" >立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
 
<script>
$(document).ready(function() {
   
      var name = $("#typename");
        // res = false;
      name.blur(function(){

       var name_val=name.val();
       var id = $('input[type="hidden"]').val();
        if (name_val == "") {
          document.getElementById("span").innerHTML = "<p>品牌不能为空</p>";
          return;
        }
        $.ajax({
          type:"post",
          data:{ type_name:name_val,type_id:id},
          url:"{url('run/type/ajaxUpdate')}",
          success:function(msg){
            if(msg==true){
              document.getElementById("span").innerHTML = "<font color='red'>品牌已存在</font>";
              $('#btn').addClass('layui-btn-disabled');
              $('#btn').attr('onclick','return false');
            }
            else{
              document.getElementById("span").innerHTML = "<font color='green'>品牌可以使用</font>";
              $('#btn').removeClass('layui-btn-disabled');
              $('#btn').attr('onclick','return true');
            }
          },
          error:function(msg){
            // alert(msg);
          }

        })
      })
 });
     /* name.blur(function() {
        var text = name.val();
         if (text == "") {
          document.getElementById("span").innerHTML = "<p>用户名不能为空</p>";
          return;
         } else {
          $.post(
              "ajaxSelect?typeName="
                + text,
              null,
              function(result) {
               var obj=eval("("+result+")");//解析JSON格式字符串
               //alert(obj["result"]);//获取JSON字符串中的某一元素
               alert(result);
               var json=JSON.parse(result);//解析JSON字符串
               //alert(json.result);
               if (json.result!=1) {
                document.getElementById("span").innerHTML = "<font color='green'>用户名可以用</font>";
               } else {
                document.getElementById("span").innerHTML = "<font color='red'>用户名已存在</font>";
               }
              });
         }
        });*/
pic();
    
</script>



{/block}